import 'dart:io';

import 'package:detect_proxy_setting/detect_proxy_setting.dart';

export 'api.dart';
export 'apis.dart';
export 'error_code.dart';
export 'result_state_mixin.dart';
export 'api/result.dart';
export 'api/http_manager.dart';
export 'http_url.dart';


///获取代理配置
Future<Map<String, String>?> getLocalProxy() async {

  final setting = await proxySetting();
  if (setting == null) {
    return null;
  }

  List<String> proxyComponents;
  if (Platform.isWindows) {
    var proxyHttp = setting.proxy.substring(setting.proxy.lastIndexOf('=') + 1);
    proxyComponents = proxyHttp.split(':');
  } else {
    proxyComponents = setting.proxy.split(':');
  }

  if (proxyComponents.length != 2) {
    return null;
  }
  return <String, String>{
    "host": proxyComponents.first,
    "port": proxyComponents.last,
  };
}
